import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post } from '@midwayjs/core';
import { Validate } from '@midwayjs/validate';
import { NotifyDTO, ReadNotifyDTO } from '../../dto/notify';
import { RouterService } from '../../service/router/router';

/**
 * 通知
 */
@CoolController()
export class NotifyController extends BaseController {
    @Inject()
    RouterService: RouterService;

    /**
     * 课程通知查询
     * @param year 学年
     * @param term 学期
     */
    @Post('/notify', { summary: '通知查询' })
    @Validate()
    async get_notify(@Body() params: NotifyDTO) {
        const { read } = params;
        const { success, message, data } = await this.RouterService.get_notify(read);
        if (!success) return this.fail(data, message);
        return this.ok(data, message);
    }

    /**
     * 阅读通知
     * @param id 通知ID
     */
    @Post('/read_notify', { summary: '阅读通知' })
    @Validate()
    async read_notify(@Body() params: ReadNotifyDTO) {
        const { id } = params;
        const { success, message, data } = await this.RouterService.read_notify(id);
        if (!success) return this.fail(data, message);
        return this.ok(data, message);
    }
}